package com.zhisheng.products.controller;


import com.zhisheng.products.entity.Products;
import com.zhisheng.products.service.ProductsService;
import com.zhisheng.result.MyResponseResult;
import com.zhisheng.users.entity.Users;
import com.zhisheng.utils.MyThreadLocal;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * (Products)表控制层
 *
 * @author 全哥
 * @since 2025-02-22 15:21:07
 */
@RestController
@RequestMapping("products")
public class ProductsController {
    /**
     * 服务对象
     */
    @Resource
    private ProductsService productsService;

    @GetMapping("/{pid}")
    public MyResponseResult<Products> getProductById(@PathVariable Integer pid){
        Users users = MyThreadLocal.get();
        System.out.println(users);
        Products byId = productsService.getById(pid);
        return MyResponseResult.success(byId);
    }

    @PostMapping("/add")
    public MyResponseResult<String> addProduct(@RequestBody Products products){
        boolean save = productsService.save(products);
        if (save){
            return MyResponseResult.success("添加成功");
        }
        return MyResponseResult.fail("添加失败");
    }

    @PutMapping("kouJian")
    public MyResponseResult<String> kouJian(@RequestBody Map<Integer,Integer> goods){
        return productsService.kouJian(goods);
    }


}

